<?php
require_once dirname(__FILE__) . '/common.inc.php';
  
header('Content-Type: text/plain');

$myPdo = DbUtils::createPdoInst();

$q = json_decode(MiscUtils::getParam('q', NULL));
try {
  $myPdo->beginTransaction();
  foreach ($q as &$tmp) {
    foreach ($tmp->a as &$obj) {
      if (isset($obj->id)) {
        DbUtils::update($myPdo, $tmp->n, $obj);
      } else {
        DbUtils::add($myPdo, $tmp->n, $obj);
      }
    }
    foreach ($tmp->r as &$obj) {
      DbUtils::delete($myPdo, $tmp->n, $obj);
    }
  }
  $myPdo->commit();
  echo json_encode(array());
} catch (PDOException $e) {
  $myPdo->rollBack();
  echo ERROR_SIGN . $e->getMessage();
}
?>